var util = require('../../libs/util.js');
var app = getApp()
Page({
  data: {
    hidden: true,
    total: 0,
    searchVal:'',
    searchAll: true,
    is_verify: false,
    verify: false
  },
  onShareAppMessage: function () {
    return {
      title: app.appName,
      path: '/pages/index/index'
    }
  },
  onLoad(e) {
    var that = this;
    wx.setNavigationBarTitle({ "title": app.appName +"--司机管理" });
    if (e.filter) {
      that.setData({
        filter: true
      })
      if (e.filter == 'carrier') {
        that.setData({
          carrier_coid: e.carrier_coid
        })
      }
    }

    let list = [];
    for (let i = 0; i < 26; i++) {
      list[i] = String.fromCharCode(65 + i)
    }
    that.setData({
      list: list,
      listCur: list[0]
    });
    this.loadData();
  },
  loadData: function () {
    var that = this;
    wx.showLoading({
      title: '请稍候...',
    });
    util.getData("/wechat/driver/getDriverList", {
      CO_ID: app.globalData.CO_ID,
      searchVal: that.data.searchVal,
      is_verify: that.data.is_verify,
      carrier_coid: that.data.carrier_coid
    }, function (res) {
      console.log(res.data.data)
      if (res.data.success) {
        that.setData({
          hasData: true,
          data: res.data.data,
          total: res.data.total
        })
      } else {
        that.setData({
          data:[],
          hasData: false
        })
      }
      wx.hideLoading();
    });
  },
  onReady() {
    let that = this;
  },
  bindInput: function (e) {
    var item = String(e.currentTarget.id), item_value = {};
    item_value[item] = e.detail.value;
    this.setData(item_value);
  },
  searchFilterAll: function () {
    // this.setData({
    //   searchAll:true,
    //   searchVal:'',
    //   is_verify: '',
    //   is_signing: '',
    //   is_employee: ''
    // })
    // this.loadData();
  },
  searchFilterVerify: function () {
    // var is_verify = !this.data.is_verify;
    // this.setData({
    //   searchAll: is_verify == false ? true : false,
    //   is_verify: is_verify == true ? '0' : false,
    //   verify: is_verify == true ? true : false
    // })
    // this.loadData();
  },
  searchFilterSigning: function () {
    // var is_signing = !this.data.is_signing;
    // this.setData({
    //   searchAll: is_signing == false ? true : false,
    //   is_signing: is_signing == true ? '0' : false,
    //   signing: is_signing == true ? true : false
    // })
    // this.loadData();
  },
  searchFilterEmployee: function () {
    // var is_employee = !this.data.is_employee;
    // this.setData({
    //   searchAll: is_employee == false ? true : false,
    //   is_employee: is_employee == true ? '0' : false,
    //   employee: is_employee == false ? true : false
    // })
    // this.loadData();
  },
  driverSearch:function(){
    console.log(this.data.searchVal)
    this.loadData();
  },
  //获取文字信息
  getCur(e) {
    this.setData({
      hidden: false,
      listCur: this.data.list[e.target.id],
    })
  },

  setCur(e) {
    this.setData({
      hidden: true,
      listCur: this.data.listCur
    })
  },
  //滑动选择Item
  tMove(e) {
    let y = e.touches[0].clientY,
      offsettop = this.data.boxTop,
      that = this;
    //判断选择区域,只有在选择区才会生效
    if (y > offsettop) {
      let num = parseInt((y - offsettop) / 20);
      this.setData({
        listCur: that.data.list[num]
      })
    };
  },

  //触发全部开始选择
  tStart() {
    this.setData({
      hidden: false
    })
  },

  //触发结束选择
  tEnd() {
    this.setData({
      hidden: true,
      listCurID: this.data.listCur
    })
  },
  indexSelect(e) {
    let that = this;
    let barHeight = this.data.barHeight;
    let list = this.data.list;
    let scrollY = Math.ceil(list.length * e.detail.y / barHeight);
    for (let i = 0; i < list.length; i++) {
      if (scrollY < i + 1) {
        that.setData({
          listCur: list[i],
          movableY: i * 20
        })
        return false
      }
    }
  }
});